import sys, os, time, copy
from PyQt4 import QtCore, QtGui
from QtHoover_main import *

global fuzzerList, loggingSettings, duplOpts, interfaces, proxy, fuzzerOpts
global currentFuzzer, inPacketNro, outPacketNro, paused, filtering
proxy = False
paused = False
inPacketNro = 0
outPacketNro = 0
fuzzerList = []
currentFuzzer = []
interfaces = ["",""]
filtering = {'enabled':False,'level':0,'sa':'','da':'','sp':0,'dp':0,'protocols':[]}
duplOpts = {'state':False, 'p':0.02}
loggingSettings = {'logfile':'','mode':'default','enabled':False,'shortName':''}
fuzzerOpts = []


class definitelyUsefulGraph(QtGui.QWidget):
    def __init__(self,parent=None):
        super(definitelyUsefulGraph,self).__init__(parent)
        self.setWindowTitle('Graph showing something relevant')
        self.setGeometry(200,175,600,400)
        grid = QtGui.QGridLayout()
        self.createGraph(grid)
        self.setLayout(grid)

    def createGraph(self, layout):
        '''
        QPixMap can to inserted into QLabel or QPushButton.
        Here QLabel is used to display the graph inside the gridlayout.
        '''
        graphLabel = QtGui.QLabel("")
        self.graph = QtGui.QPixmap(580,340)

        exitButton = QtGui.QPushButton('&Exit')
        self.connect(exitButton,QtCore.SIGNAL('clicked()'),QtCore.SLOT('close()'))

        clearButton = QtGui.QPushButton('&Clear graph')

        statsButton = QtGui.QPushButton('&Show statistics')

        '''Actual magic happens here'''
        self.graph.fill(QtGui.QColor(190,220,190))
        
        paint = QtGui.QPainter()
        height = self.graph.height()
        width = self.graph.width()
        paint.begin(self.graph)
        paint.setPen(QtGui.QColor('darkGray'))
        for i in range(height/10, height, height/10):
            paint.drawLine(10,i,width-7,i)
        for i in range(width/10, width, width/10):
            paint.drawLine(i, 7, i, height-10)
        
        #Draw bolder axes
        pen = QtGui.QPen(QtGui.QColor(0,0,0))
        pen.setWidth(3)
        paint.setPen(pen)
        paint.drawLine(7,7,7,height-7)
        paint.drawLine(7,height-7,width-7,height-7)
        
        paint.end()
        '''Magic ends here'''

        graphLabel.setPixmap(self.graph)
        graphLabel.setStyleSheet("QLabel {border:1px solid darkGray;border-radius:5px;}")
        graphLabel.setScaledContents(True)
        
        layout.addWidget(graphLabel,0,0,1,3)
        layout.addWidget(exitButton,1,0)
        layout.addWidget(clearButton,1,1)
        layout.addWidget(statsButton,1,2)

    def updateGraph(self):
        pass

    def clearGraph(self):
        pass


class sessionReplay(QtGui.QWidget):
    def __init__(self,parent=None):
        super(sessionReplay,self).__init__(parent)
        self.setWindowTitle('Replicate session')
        grid = QtGui.QGridLayout()
        self.createWidgets(grid)
        self.setLayout(grid)

    def createWidgets(self,layout):
        okButton = QtGui.QPushButton('&Ok')

        cancelButton = QtGui.QPushButton('&Cancel')
        self.connect(cancelButton,QtCore.SIGNAL('clicked()'),QtCore.SLOT('close()'))

        layout.addWidget(okButton,1,0)
        layout.addWidget(cancelButton,1,1)


class filterSettings(QtGui.QWidget):

    updateSignal = QtCore.pyqtSignal()
    
    def __init__(self,parent=None):
        super(filterSettings,self).__init__(parent)
        self.setWindowTitle('Filtering settings')
        self.activated = False
        grid = QtGui.QGridLayout()
        self.createWidgets(grid)
        self.setLayout(grid)

    def createWidgets(self, layout):
        self.group0 = QtGui.QGroupBox('')
        self.group0.setStyle(QtGui.QStyleFactory.create('Plastique'))
        self.group = QtGui.QGroupBox("Protocol filtering")
        self.group.setStyle(QtGui.QStyleFactory.create('Plastique'))
        self.group2 = QtGui.QGroupBox("Parsing level")
        self.group2.setStyle(QtGui.QStyleFactory.create('Plastique'))
        self.group3 = QtGui.QGroupBox("Other options")
        self.group3.setStyle(QtGui.QStyleFactory.create('Plastique'))

        groupGrid = QtGui.QGridLayout()

        self.enableFiltering = QtGui.QCheckBox('Enable filtering')
        self.connect(self.enableFiltering,QtCore.SIGNAL('clicked()'),self.setStates)       
        if filtering['enabled']:
            self.activated = False
        else:
            self.activated = True

        HBox1 = QtGui.QHBoxLayout()

        self.udpCheck = QtGui.QCheckBox('UDP')
        
        self.tcpCheck = QtGui.QCheckBox('TCP')

        HBox1.addWidget(self.udpCheck)
        HBox1.addWidget(self.tcpCheck)

        self.group.setLayout(HBox1)

        HBox2 = QtGui.QHBoxLayout()

        self.level0 = QtGui.QRadioButton('Default')

        self.level1 = QtGui.QRadioButton('level 1')

        self.level2 = QtGui.QRadioButton('level 2')

        self.level3 = QtGui.QRadioButton('level 3')

        HBox2.addWidget(self.level0)
        HBox2.addWidget(self.level1)
        HBox2.addWidget(self.level2)
        HBox2.addWidget(self.level3)

        self.group2.setLayout(HBox2)

        GBox = QtGui.QGridLayout()

        self.saCheck = QtGui.QCheckBox('Enable')
        self.connect(self.saCheck,QtCore.SIGNAL('clicked()'),self.setOtherState)
        self.saEdit = QtGui.QLineEdit(maxLength=20)
        self.saEdit.setFixedSize(120,27)

        self.daCheck = QtGui.QCheckBox('Enable')
        self.connect(self.daCheck,QtCore.SIGNAL('clicked()'),self.setOtherState)
        self.daEdit = QtGui.QLineEdit(maxLength=20)
        self.daEdit.setFixedSize(120,27)

        self.spCheck = QtGui.QCheckBox('Enable')
        self.connect(self.spCheck,QtCore.SIGNAL('clicked()'),self.setOtherState)
        self.spEdit = QtGui.QLineEdit(maxLength=5)
        self.spEdit.setFixedSize(50,27)

        self.dpCheck = QtGui.QCheckBox('Enable')
        self.connect(self.dpCheck,QtCore.SIGNAL('clicked()'),self.setOtherState)
        self.dpEdit = QtGui.QLineEdit(maxLength=5)
        self.dpEdit.setFixedSize(50,27)

        emptyVSpace = QtGui.QLabel('')
        emptyVSpace.setFixedWidth(35)
        emptyHSpace = QtGui.QLabel('')
        emptyHSpace.setFixedHeight(10)

        GBox.addWidget(QtGui.QLabel('Source address'),0,0,1,2)
        GBox.addWidget(self.saCheck,1,0)
        GBox.addWidget(self.saEdit,1,1)
        GBox.addWidget(QtGui.QLabel('Destination address'),3,0,1,2)
        GBox.addWidget(self.daCheck,4,0)
        GBox.addWidget(self.daEdit,4,1)
        GBox.addWidget(emptyVSpace,0,2,4,1)
        GBox.addWidget(emptyHSpace,2,0,1,5)
        GBox.addWidget(QtGui.QLabel('Source port'),0,3,1,2)
        GBox.addWidget(self.spCheck,1,3)
        GBox.addWidget(self.spEdit,1,4)
        GBox.addWidget(QtGui.QLabel('Destination port'),3,3,1,2)
        GBox.addWidget(self.dpCheck,4,3)
        GBox.addWidget(self.dpEdit,4,4)

        self.group3.setLayout(GBox)

        okButton = QtGui.QPushButton('&OK')
        self.connect(okButton,QtCore.SIGNAL('clicked()'),self.saveStates)

        cancelButton = QtGui.QPushButton('&Cancel')
        self.connect(cancelButton,QtCore.SIGNAL('clicked()'),QtCore.SLOT('close()'))

        groupGrid.addWidget(self.enableFiltering,0,0)
        groupGrid.addWidget(self.group2,1,0,1,3)
        groupGrid.addWidget(self.group,2,0,1,3)
        groupGrid.addWidget(self.group3,3,0,1,3)

        self.group0.setLayout(groupGrid)

        layout.addWidget(self.group0,0,0,3,3)
        layout.addWidget(okButton,4,0)
        layout.addWidget(cancelButton,4,2)

        self.setStates()

    def setOtherState(self):
        if self.saCheck.checkState(): self.saEdit.setEnabled(True)
        else: self.saEdit.setEnabled(False)

        if self.daCheck.checkState(): self.daEdit.setEnabled(True)
        else: self.daEdit.setEnabled(False)

        if self.spCheck.checkState(): self.spEdit.setEnabled(True)
        else: self.spEdit.setEnabled(False)

        if self.dpCheck.checkState(): self.dpEdit.setEnabled(True)
        else: self.dpEdit.setEnabled(False)

    def setStates(self):
        if self.activated:
            self.activated = False
            self.enableFiltering.setChecked(False)
            self.group.setEnabled(False)
            self.group2.setEnabled(False)
            self.group3.setEnabled(False)
        else:
            self.activated = True
            self.enableFiltering.setChecked(True)
            self.group.setEnabled(True)
            self.group2.setEnabled(True)
            self.group3.setEnabled(True)
            self.setOtherState()

            if filtering['level']==0: self.level0.setChecked(True)
            elif filtering['level']==1: self.level1.setChecked(True)
            elif filtering['level']==2: self.level2.setChecked(True)
            elif filtering['level']==3: self.level3.setChecked(True)

            if 'udp' in filtering['protocols']: self.udpCheck.setChecked(True)
            if 'tcp' in filtering['protocols']: self.tcpCheck.setChecked(True)

            if filtering['sa']!="":
                self.saCheck.setChecked(True)
                self.saEdit.setEnabled(True)
                self.saEdit.setText(filtering['sa'])
            if filtering['da']!="":
                self.daCheck.setChecked(True)
                self.daEdit.setEnabled(True)
                self.daEdit.setText(filtering['da'])
            if filtering['sp']!=0:
                self.spCheck.setChecked(True)
                self.spEdit.setEnabled(True)
                self.spEdit.setText(str(filtering['sp']))
            if filtering['dp']!=0:
                self.dpCheck.setChecked(True)
                self.dpEdit.setEnabled(True)
                self.dpEdit.setText(str(filtering['sp']))

    def saveStates(self):
        global filtering

        if self.enableFiltering.isChecked():
            filtering['enabled'] = True
        else: filtering['enabled'] = False
        
        if self.level0.isChecked(): filtering['level']=0
        elif self.level1.isChecked(): filtering['level']=1
        elif self.level2.isChecked(): filtering['level']=2
        elif self.level3.isChecked(): filtering['level']=3

        filtering['protocols'] = []
        if self.udpCheck.isChecked(): filtering['protocols'].append('udp')
        if self.tcpCheck.isChecked(): filtering['protocols'].append('tcp')
                
        try:
            if self.saCheck.isChecked():
                temp = str(self.saEdit.displayText())
                if len(temp)==0: raise Exception
                filtering['sa'] = temp
            else: filtering['sa'] = ''
            if self.daCheck.isChecked():
                temp = str(self.daEdit.displayText())
                if len(temp)==0: raise Exception
                filtering['da'] = temp
            else: filtering['da'] = ''
            if self.spCheck.isChecked():
                temp = int(self.spEdit.displayText())
                if temp<=0 or temp>65535: raise Exception
                filtering['sp'] = temp
            else: filtering['sp'] = 0
            if self.dpCheck.isChecked():
                temp = int(self.dpEdit.displayText())
                if temp<=0 or temp>65535: raise Exception
                filtering['dp'] = temp
            else: filtering['dp'] = 0
        except Exception:
            warning = displayWarning('Erronous option values')
            warning.exec_()
            return

        self.updateSignal.emit()
        self.close()


class logSettings(QtGui.QWidget):

    updateSignal = QtCore.pyqtSignal()
    
    def __init__(self, parent=None):
        super(logSettings,self).__init__(parent)
        self.setWindowTitle('Log settings')
        self.setGeometry(100,125,250,150)
        grid = QtGui.QGridLayout()
        self.logging(grid)
        self.setLayout(grid)
        

    def logging(self,layout):
        
        group = QtGui.QGroupBox('Logging format')
        group.setStyle(QtGui.QStyleFactory.create('Plastique'))
        group2 = QtGui.QGroupBox('Logfile')
        group2.setStyle(QtGui.QStyleFactory.create('Plastique'))
        group3 = QtGui.QGroupBox('Logging')
        group3.setStyle(QtGui.QStyleFactory.create('Plastique'))

        box = QtGui.QHBoxLayout()
        box2 = QtGui.QVBoxLayout()
        box3 = QtGui.QVBoxLayout()

        self.format1 = QtGui.QRadioButton('Default')
        if loggingSettings['mode']=='default':
            self.format1.setChecked(True)

        self.format2 = QtGui.QRadioButton('Pcap')
        if loggingSettings['mode']=='pcap':
            self.format2.setChecked(True)

        box.addWidget(self.format1)
        box.addWidget(self.format2)
        group.setLayout(box)

        self.logLabel = QtGui.QLabel('')
        if loggingSettings['logfile']!='':
            self.logLabel.setText("Logfile: '{}'".format(loggingSettings['shortName']))
        else:
            self.logLabel.setText("Logfile: 'None'")
        self.logfileButton = QtGui.QPushButton('Select logfile')
        self.connect(self.logfileButton,QtCore.SIGNAL('clicked()'),self.logfileLocation)

        box2.addWidget(self.logLabel)
        box2.addWidget(self.logfileButton)
        group2.setLayout(box2)
        
        self.okButton = QtGui.QPushButton('&Ok')
        self.connect(self.okButton,QtCore.SIGNAL('clicked()'),self.saveSettings)
        
        self.cancelButton = QtGui.QPushButton('&Cancel')
        self.connect(self.cancelButton,QtCore.SIGNAL('clicked()'),QtCore.SLOT('close()'))

        self.enableBox = QtGui.QCheckBox('Enable logging')
        self.connect(self.enableBox,QtCore.SIGNAL('clicked()'),self.loggingCheck)
        if loggingSettings['enabled']:
            self.enableBox.setCheckState(QtCore.Qt.Checked)
        self.loggingCheck()

        box3.addWidget(self.enableBox)
        box3.addWidget(group)
        box3.addWidget(group2)
        group3.setLayout(box3)

        layout.addWidget(group3,0,0,1,2)
        layout.addWidget(self.okButton,2,0)
        layout.addWidget(self.cancelButton,2,1)


    def loggingCheck(self):
        
        global loggingSettings
        if self.enableBox.checkState():
            loggingSettings['enabled'] = True
            self.logfileButton.setEnabled(True)
            self.format1.setEnabled(True)
            self.format2.setEnabled(True)
            self.logLabel.setEnabled(True)
        else:
            loggingSettings['enabled'] = False
            self.logfileButton.setEnabled(False)
            self.format1.setEnabled(False)
            self.format2.setEnabled(False)
            self.logLabel.setEnabled(False)


    def saveSettings(self):
        
        global loggingSettings
        if self.format2.isChecked(): loggingSettings['mode']='pcap'
        self.updateSignal.emit()
        self.close()


    def logfileLocation(self):
        
        global loggingSettings
        logfile = QtGui.QFileDialog.getSaveFileName(self,'Open logfile','/home')
        loggingSettings['logfile'] = logfile
        loggingSettings['shortName'] = logfile.split('/')[len(logfile.split('/'))-1]
        self.logLabel.setText("Logfile: '{}'".format(loggingSettings['shortName']))
        

'''Class which is used for displaying separate window with fuzzers and their
settings which can be set and manipulated'''
class fuzzerChoice(QtGui.QWidget):

    updateSignal = QtCore.pyqtSignal()
    
    def __init__(self, parent=None):
        super(fuzzerChoice,self).__init__(parent)
        self.setWindowTitle('Fuzzers')
        grid = QtGui.QGridLayout()
        self.fChoice(grid)
        self.setLayout(grid)
        self.advFuzzerOpts = False
        #self.resize(450,400)

    def fChoice(self,layout):
        '''Layouts and styles'''
        group = QtGui.QGroupBox('Available fuzzers')
        group.setStyle(QtGui.QStyleFactory.create('Plastique'))
        group2 = QtGui.QGroupBox('Duplicate packets')
        group2.setStyle(QtGui.QStyleFactory.create('Plastique'))

        Gbox2 = QtGui.QGridLayout()
        Gbox = QtGui.QGridLayout()

        advFuzzBox = QtGui.QGridLayout()
        self.advGroup = QtGui.QGroupBox()
        self.advGroup.setStyle(QtGui.QStyleFactory.create('Plastique'))
        
        labelStyle="QPushButton{font-size:10px;text-decoration:underline;color:blue;}"

        '''Widgets and their settings'''
        self.advOptsButton = QtGui.QPushButton('Advanced options')
        self.connect(self.advOptsButton,QtCore.SIGNAL('clicked()'),self.advancedOptions)
        self.advOptsButton.setStyleSheet(labelStyle)
        self.advOptsButton.setFlat(True)
        self.advOptsButton.setFocusPolicy(QtCore.Qt.NoFocus)

        self.fuzzerCombo = QtGui.QComboBox()
        self.fuzzerCombo.setFixedSize(100,27)
        self.fuzzerCombo.addItem("-----")
        self.fuzzerCombo.addItem("Flipr")
        self.fuzzerCombo.addItem("Rambo")
        self.fuzzerCombo.addItem("DistFuzz")
        self.fuzzerCombo.currentIndexChanged[int].connect(self.setAdvancedOptionValues)

        #Incrementation
        self.FuzzInc = QtGui.QCheckBox('Increment')
        self.connect(self.FuzzInc,QtCore.SIGNAL('clicked()'),self.saveAdvancedOptions)
        #Fuzzfactor slider and textedit
        self.FuzzFf = QtGui.QSlider(QtCore.Qt.Horizontal)
        self.FuzzFf.setMinimum(1)
        self.FuzzFf.setMaximum(100)
        self.FuzzFf.setFocusPolicy(QtCore.Qt.NoFocus)
        self.FuzzFf.valueChanged[int].connect(self.FuzzerValue)
        self.FuzzFf.valueChanged[int].connect(self.saveAdvancedOptions)
        self.FuzzEdit = QtGui.QLineEdit(maxLength=3)
        self.FuzzEdit.setFixedSize(37,27)
        self.FuzzEdit.textChanged[QtCore.QString].connect(self.FuzzerValue)

        advFuzzBox.addWidget(QtGui.QLabel("<b>Fuzzer:</b>"),0,0)
        advFuzzBox.addWidget(self.fuzzerCombo,0,1)
        advFuzzBox.addWidget(QtGui.QLabel("Fuzzfactor%"),1,0,1,2,QtCore.Qt.AlignBottom)
        advFuzzBox.addWidget(self.FuzzFf,2,0,QtCore.Qt.AlignTop)
        advFuzzBox.addWidget(self.FuzzEdit,2,1,QtCore.Qt.AlignTop)
        advFuzzBox.addWidget(self.FuzzInc,3,0,1,2,QtCore.Qt.AlignHCenter)
        self.FuzzFf.setValue(2)
        self.FuzzEdit.setText("2")

        self.advGroup.setLayout(advFuzzBox)
        self.advGroup.setVisible(False)

        self.Flipr = QtGui.QCheckBox('Flipr')
        
        self.Enumr = QtGui.QCheckBox('Enumr')

        self.Rambo = QtGui.QCheckBox('Rambo')

        self.Range = QtGui.QCheckBox('Range')

        self.DistFuzz = QtGui.QCheckBox('DistFuzz')

        if 'Flipr' in fuzzerList:
            self.Flipr.setCheckState(QtCore.Qt.Checked)
        if 'Enumr' in fuzzerList:
            self.Enumr.setCheckState(QtCore.Qt.Checked)
        if 'Rambo' in fuzzerList:
            self.Rambo.setCheckState(QtCore.Qt.Checked)
        if 'Range' in fuzzerList:
            self.Range.setCheckState(QtCore.Qt.Checked)
        if 'DistFuzz' in fuzzerList:
            self.DistFuzz.setCheckState(QtCore.Qt.Checked)

        Gbox2.addWidget(self.Flipr,0,0,1,2)
        Gbox2.addWidget(self.advOptsButton,0,2)
        Gbox2.addWidget(self.Enumr,1,0,1,2)
        Gbox2.addWidget(self.Rambo,2,0,1,2)
        Gbox2.addWidget(self.Range,3,0,1,2)
        Gbox2.addWidget(self.DistFuzz,4,0,1,2)

        self.Duplicator = QtGui.QCheckBox('Allow duplicating')
        self.connect(self.Duplicator,QtCore.SIGNAL('clicked()'),self.acceptDupl)

        self.DuplP = QtGui.QLineEdit(maxLength=5)
        self.DuplP.setFixedSize(45,27)

        if duplOpts['state']:
            self.Duplicator.setCheckState(QtCore.Qt.Checked)
            self.DuplP.setText(repr(duplOpts['p']))
        else:
            self.DuplP.setEnabled(False)

        Gbox.addWidget(self.Duplicator,0,0,1,2)
        Gbox.addWidget(QtGui.QLabel('Probability%:'),1,0)
        Gbox.addWidget(self.DuplP,1,1)

        group.setLayout(Gbox2)
        group2.setLayout(Gbox)

        self.helpButton = QtGui.QPushButton('&Help')
        self.connect(self.helpButton,QtCore.SIGNAL('clicked()'),self.displayHelp)

        self.okButton = QtGui.QPushButton('&Ok')
        self.connect(self.okButton,QtCore.SIGNAL('clicked()'),self.saveValues)
        
        self.cancelButton = QtGui.QPushButton('&Cancel')
        self.connect(self.cancelButton,QtCore.SIGNAL('clicked()'),QtCore.SLOT('close()'))

        layout.addWidget(group,0,0,1,2)
        layout.addWidget(group2,1,0,1,2)
        layout.addWidget(self.advGroup,0,2,1,2)
        layout.addWidget(self.helpButton,2,0,1,2)
        layout.addWidget(self.okButton,3,0)
        layout.addWidget(self.cancelButton,3,1)


    def saveAdvancedOptions(self, value=0):
        
        global fuzzerOpts
        fuzzers = ["","Flipr","Rambo","DistFuzz"]
        #1 = Flipr, 2 = Rambo, 3 = DistFuzz
        cIndex = self.fuzzerCombo.currentIndex()
        if cIndex!=0:
            if self.FuzzInc.isChecked():
                if fuzzers[cIndex]+"-increment" not in fuzzerOpts:
                    fuzzerOpts.append(fuzzers[cIndex]+"-increment")
            else:
                if fuzzers[cIndex]+"-increment" in fuzzerOpts:
                    fuzzerOpts.pop(fuzzerOpts.index(fuzzers[cIndex]+"-increment"))

            if value!=0:
                if fuzzers[cIndex]+"-fuzzfactor" not in fuzzerOpts:
                    fuzzerOpts.append(fuzzers[cIndex]+"-fuzzfactor")
                    fuzzerOpts.append(str(float(value)/100))
                else:
                    fuzzerOpts[fuzzerOpts.index(fuzzers[cIndex]+"-fuzzfactor")+1]=str(float(value)/100)

            
    def setAdvancedOptionValues(self, index):
        
        fuzzers = ["","Flipr","Rambo","DistFuzz"]
        if index!=0:
            self.FuzzInc.setEnabled(True)
            self.FuzzEdit.setEnabled(True)
            self.FuzzFf.setEnabled(True)

            if fuzzers[index]+"-increment" in fuzzerOpts:
                self.FuzzInc.setCheckState(QtCore.Qt.Checked)
            else: self.FuzzInc.setCheckState(QtCore.Qt.Unchecked)

            if fuzzers[index]+"-fuzzfactor" in fuzzerOpts:
                self.FuzzEdit.setText(str(int(float(fuzzerOpts[fuzzerOpts.index(fuzzers[index]+"-fuzzfactor")+1])*100)))
            else: self.FuzzEdit.setText("2")
        else:
            self.FuzzInc.setEnabled(False)
            self.FuzzInc.setCheckState(QtCore.Qt.Unchecked)
            self.FuzzEdit.setEnabled(False)
            self.FuzzFf.setEnabled(False)


    def advancedOptions(self):
        
        if self.advGroup.isVisible():
            self.advGroup.setVisible(False)
            self.resize(257,370)
            self.advFuzzerOpts = False
        else:
            self.advGroup.setVisible(True)
            self.resize(465,370)
            self.advFuzzerOpts = True


    def FuzzerValue(self, value):
        
        if str(type(value))=="<type 'int'>":
            self.FuzzEdit.setText(str(value))
        elif str(type(value))=="<class 'PyQt4.QtCore.QString'>":
            try:
                self.FuzzFf.setValue(int(value))
            except ValueError:
                self.FuzzFf.setValue(1)


    '''Displays helpful information concerning fuzzers'''
    def displayHelp(self):
        
        helpStyle="QMessageBox{border-radius:7px;border:8px groove gray;background:lightgray;}"

        helpBox = QtGui.QMessageBox()
        helpBox.setWindowTitle("Fuzzer information")

        info = QtCore.QString()
        info.append("<h3>Available fuzzers and further information</h3>&nbsp;&nbsp;&nbsp;<br/><br/>")
        info.append("<b>Flipr:</b> The byte flipper.<br/>Flipr randomly selects some places from the samples and flips some randomly chosen bit. The amount of flips depends on the fuzzfactor.<br/><br/>")
        info.append("<b>Enumr:</b> The byte enumerator.<br/>Enumr just starts from byte 0 and moves to byte 1 and so on. It doesn't need any input to function.<br/><br/>")
        info.append("<b>Rambo:</b> The file mutator.<br/>Rambo uses probably the most common fuzzing technique. It selects some random places from a randomly picked sample and removes, repeats, or replaces a byte. The amount of mutations depends on the fuzzfactor.<br/><br/>")
        info.append("<b>Range:</b> The random data generator.<br/>Range generates a test case filled with pseudo-random content.<br/><br/>")
        info.append("<b>DistFuzz:</b> Fuzzer based on byte distribution.<br/>Distfuzz calculates the byte distribution of all samples and generates test cases so that more probable bytes are more probable in the test cases. It also, depending on the fuzzfactor, inserts some pseudo-random bytes in some places.<br/><br/>")
        info.append("<b>Duplicates:</b> The packet duplicator.<br/>Sends the same package twice. Whether the package is duplicated or not is decided once the package has arrived. The probability variable tells how probable it is to duplicate each incoming package.<br/>")

        helpBox.setStyleSheet(helpStyle)
        helpBox.setText(info)
        helpBox.exec_()
        

    def acceptDupl(self):
        
        global duplOpts
        if duplOpts['state']:
            duplOpts['state'] = False
            self.DuplP.setEnabled(False)
        else:
            duplOpts['state'] = True
            self.DuplP.setEnabled(True)
            self.DuplP.setText(repr(duplOpts['p']))
            

    def saveValues(self):
        
        global fuzzerList, duplOpts, fuzzerOpts
        fuzzerList = []

        if not self.advGroup.isVisible():
            fuzzerOpts = []
        
        if self.Flipr.checkState(): fuzzerList.append('Flipr')
        if self.Enumr.checkState(): fuzzerList.append('Enumr')
        if self.Rambo.checkState(): fuzzerList.append('Rambo')
        if self.Range.checkState(): fuzzerList.append('Range')
        if self.DistFuzz.checkState(): fuzzerList.append('DistFuzz')

        if duplOpts['state']:
            temp = self.DuplP.displayText()
            try:
                duplOpts['p'] = float(temp)
                if duplOpts['p']>1 or duplOpts['p']<0.01:
                    raise Exception
            except Exception:
                warning = displayWarning('Value has to be in range [0.01, 1.0]')
                warning.exec_()
                return

        global currentFuzzer
        currentFuzzer = copy.deepcopy(fuzzerList)
        self.updateSignal.emit()
        self.close()
        

'''
Main class for network hoover.
Creates the main window and acts as an interface between all the components
in the hoover's GUI.
'''
class NetworkHoover(QtGui.QMainWindow):

    rotateFuzzerSignal = QtCore.pyqtSignal(int)
    
    def __init__(self):
        QtGui.QMainWindow.__init__(self)

        self.operate = False
        self.packetInfo = False

        self.disabledText = QtCore.QString("<font style='color:red;'>disabled</font><br/>")
        self.enabledText = QtCore.QString("<font style='color: green;'>enabled</font><br/>")

        #Main window attributes
        #self.setGeometry(25,75,600,400)
        self.setWindowTitle('Network Hoover - for messing up networks')
        self.setMaximumHeight(500)

        #Grouping layouts without text to add some bling bling
        gruuppi = QtGui.QGroupBox('')
        gruuppi.setStyle(QtGui.QStyleFactory.create('Plastique'))

        gruuppi2 = QtGui.QGroupBox('')
        gruuppi2.setStyle(QtGui.QStyleFactory.create('Plastique'))

        gruuppi3 = QtGui.QGroupBox('')
        gruuppi3.setStyle(QtGui.QStyleFactory.create('Plastique'))

        #Smaller layouts
        self.buttonLayout = QtGui.QGridLayout()
        self.infoFieldLayout = QtGui.QGridLayout()
        self.generalLayout = QtGui.QGridLayout()

        self.createMainButtons(self.buttonLayout)
        self.createInfoFields(self.infoFieldLayout)
        self.createGeneralField(self.generalLayout)
        self.createBars()

        #Button which will work as a shortcut to the graph
        graphButtonStyle="QPushButton {margin:10px;border-style:none;background-color:rgb(0,200,0);border-radius:7px;}"
        self.graphButton = QtGui.QPushButton('Click this!')
        self.graphButton.setStyleSheet(graphButtonStyle)
        self.connect(self.graphButton,QtCore.SIGNAL('clicked()'),self.displayGraph)

        self.graphButton.setVisible(False) #BOMF!
        
        #Main layout manager
        mainLayout = QtGui.QGridLayout()

        gruuppi.setLayout(self.buttonLayout)
        gruuppi2.setLayout(self.infoFieldLayout)
        gruuppi3.setLayout(self.generalLayout)
        #gruuppi3.setSizePolicy(QtGui.QSizePolicy.Fixed,QtGui.QSizePolicy.Maximum)

        mainLayout.addWidget(gruuppi,0,0)
        mainLayout.addWidget(gruuppi2,1,0)
        mainLayout.addWidget(gruuppi3,0,1,2,1,QtCore.Qt.AlignTop)
        mainLayout.addWidget(self.graphButton,1,1,QtCore.Qt.AlignBottom)

        #Dummy widget to contain the layout manager
        self.mainWidget = QtGui.QWidget(self)
        self.mainWidget.setLayout(mainLayout)
        self.setCentralWidget(self.mainWidget)

        '''Setting up styles'''
        #For main window
        self.mainWidget.setAutoFillBackground(True)
        pal = QtGui.QPalette()
        color1 = QtGui.QColor('darkGreen')
        color1.setAlpha(60)
        pal.setColor(QtGui.QPalette.Window, color1)
        self.mainWidget.setPalette(pal)

        #For main layouts
        groupStyle="QGroupBox {margin-top:0px;padding:5px;background-color:lightGray;border:1px solid darkGray; border-radius:5px;}"
        gruuppi.setStyleSheet(groupStyle)
        gruuppi2.setStyleSheet(groupStyle)
        gruuppi3.setStyleSheet(groupStyle)

        #Function for converting raw package's ethernet address to readable form
        self.ethToInt = lambda x: ':'.join(["%02X" % ord(y) for y in x])
        

    def createBars(self):
        
        Exit = QtGui.QAction('Exit',self)
        Exit.setShortcut('Ctrl+Q')
        self.connect(Exit,QtCore.SIGNAL('triggered()'),QtCore.SLOT('close()'))

        Replay = QtGui.QAction('Replay session',self)
        self.connect(Replay,QtCore.SIGNAL('triggered()'),self.replay)
        
        menubar = self.menuBar()
        
        fl = menubar.addMenu('&File')
        fl.addAction(Replay)
        fl.addSeparator()
        fl.addAction(Exit)

        logS = QtGui.QAction('Log settings',self)
        logS.setShortcut('Ctrl+L')
        self.connect(logS,QtCore.SIGNAL('triggered()'),self.logging)

        flt = QtGui.QAction('Filtering',self)
        flt.setShortcut('Ctrl+F')
        self.connect(flt,QtCore.SIGNAL('triggered()'),self.filtering)

        self.proxyON = QtGui.QAction('Enable proxying',self)
        self.connect(self.proxyON,QtCore.SIGNAL('triggered()'),self.proxying)
        self.proxyOFF = QtGui.QAction('Disable proxying',self)
        self.connect(self.proxyOFF,QtCore.SIGNAL('triggered()'),self.proxying)

        sttngs = menubar.addMenu('&Settings')
        sttngs.addAction(logS)
        sttngs.addAction(flt)
        sttngs.addSeparator()
        sttngs.addAction(self.proxyON)
        sttngs.addAction(self.proxyOFF)

        global proxy
        if proxy: proxy = False
        else: proxy = True
        self.proxying()

        hl = menubar.addMenu('&Help')


    def proxying(self):
        
        global proxy
        if proxy:
            proxy = False
            self.proxyON.setVisible(True)
            self.proxyOFF.setVisible(False)
        else:
            proxy = True
            self.proxyOFF.setVisible(True)
            self.proxyON.setVisible(False)

        self.updateGeneralField()


    def filtering(self):

        self.filterSettings = filterSettings()
        self.filterSettings.show()
        self.filterSettings.updateSignal.connect(self.updateGeneralField)


    def displayGraph(self):

        self.superGraph = definitelyUsefulGraph()
        self.superGraph.show()


    def logging(self):

        self.logSetting = logSettings()
        self.logSetting.show()
        self.logSetting.updateSignal.connect(self.updateGeneralField)


    def replay(self):

        self.replay = sessionReplay()
        self.replay.show()


    def fuzzerQuery(self):

        self.fuzzerChoice = fuzzerChoice()
        self.fuzzerChoice.setMinimumWidth(250)
        self.fuzzerChoice.show()
        self.fuzzerChoice.updateSignal.connect(self.updateGeneralField)


    def createMainButtons(self, layout):

        self.resetButton = QtGui.QPushButton('Reset')
        self.resetButton.setWhatsThis('Clears current settings')
        self.connect(self.resetButton,QtCore.SIGNAL('clicked()'),self.resetSettings)
        
        '''Run Button'''
        self.runButton = QtGui.QPushButton('\nHoover\nStart\n')
        self.runButton.setFixedSize(100,93)
        self.runButton.setFocusPolicy(QtCore.Qt.NoFocus)
        self.connect(self.runButton,QtCore.SIGNAL('clicked()'),self.startHoover)

        self.runRedPalette = QtGui.QPalette()
        redGradient = QtGui.QLinearGradient()
        redGradient.setColorAt(0.0, QtGui.QColor(220,200,200))
        redGradient.setColorAt(1.0, QtGui.QColor(160,100,100))
        self.runRedPalette.setBrush(QtGui.QPalette.Button, redGradient)

        self.runGreenPalette = QtGui.QPalette()
        greenGradient = QtGui.QLinearGradient()
        greenGradient.setColorAt(0.0, QtGui.QColor(200,220,200))
        greenGradient.setColorAt(1.0, QtGui.QColor(100,160,100))
        self.runGreenPalette.setBrush(QtGui.QPalette.Button, greenGradient)

        self.runButton.setPalette(self. runGreenPalette)
        ''' --- '''
        
        self.fuzzerButton = QtGui.QPushButton('Fuzzers')
        self.fuzzerButton.setFixedSize(120,30)
        self.connect(self.fuzzerButton,QtCore.SIGNAL('clicked()'),self.fuzzerQuery)
        
        self.pauseButton = QtGui.QPushButton('Pause')
        self.pauseButton.setEnabled(False)
        self.connect(self.pauseButton,QtCore.SIGNAL('clicked()'),self.hooverPause)
        
        self.swapButton = QtGui.QPushButton('Swap')
        self.swapButton.setEnabled(False)

        self.fleft = QtGui.QPushButton('<')
        self.fleft.setFixedSize(60,23)
        self.fleft.setEnabled(False)
        self.connect(self.fleft,QtCore.SIGNAL('clicked()'),self.rotateLeft)

        self.fright = QtGui.QPushButton('>')
        self.fright.setFixedSize(60,23)
        self.fright.setEnabled(False)
        self.connect(self.fright,QtCore.SIGNAL('clicked()'),self.rotateRight)

        self.inputLine = QtGui.QLineEdit(maxLength=10)
        self.inputLine.setFixedSize(45,27)

        self.outputLine = QtGui.QLineEdit(maxLength=10)
        self.outputLine.setFixedSize(45,27)
    
        self.infoCheck = QtGui.QCheckBox('Display packet\ninformation')
        self.infoCheck.setFixedSize(150,30)
        self.infoCheck.setFocusPolicy(QtCore.Qt.NoFocus)

        layout.addWidget(self.resetButton,0,0)
        layout.addWidget(self.pauseButton,1,0)#,QtCore.Qt.AlignTop)
        layout.addWidget(self.swapButton,2,0,QtCore.Qt.AlignTop)
        layout.addWidget(self.runButton,0,1,3,1,QtCore.Qt.AlignTop)
        layout.addWidget(QtGui.QLabel(''),0,2,2,1)
        layout.addWidget(self.fuzzerButton,0,3,QtCore.Qt.AlignCenter)
        layout.addWidget(QtGui.QLabel("<b>Change fuzzer</b>"),1,3,QtCore.Qt.AlignHCenter)
        layout.addWidget(self.infoCheck,2,5,1,2,QtCore.Qt.AlignHCenter)
        layout.addWidget(QtGui.QLabel("Interfaces"),0,5,2,1,QtCore.Qt.AlignCenter)
        layout.addWidget(QtGui.QLabel('In:'),0,6,QtCore.Qt.AlignLeft)
        layout.addWidget(self.inputLine,0,6,QtCore.Qt.AlignRight)
        layout.addWidget(QtGui.QLabel('Out:'),1,6,QtCore.Qt.AlignLeft)
        layout.addWidget(self.outputLine,1,6,QtCore.Qt.AlignRight)

        box = QtGui.QHBoxLayout()
        box.addWidget(self.fleft)
        box.addWidget(self.fright)
        layout.addLayout(box,2,3,QtCore.Qt.AlignTop)

        layout.setColumnMinimumWidth(3,25)
        layout.setColumnMinimumWidth(6,50)

        layout.setColumnStretch(0,1)
        layout.setColumnStretch(1,1)
        layout.setColumnStretch(2,10)
        layout.setColumnStretch(3,1)
        layout.setColumnStretch(4,10)
        layout.setColumnStretch(6,1)


    def hooverPause(self):

        global paused
        if paused:
            paused = False
            self.Listener.hooverPause(paused)
        else:
            paused = True
            self.Listener.hooverPause(paused)


    '''Clears hoover's settings'''
    def resetSettings(self):

        global loggingSettings, fuzzerList, currentFuzzer, interfaces, proxy, duplOpts
        loggingSettings['enabled'] = False
        loggingSettings['logfile'] = ""
        loggingSettings['shortName'] = ""
        loggingSettings['mode'] = 'default'

        fuzzerList = []
        currentFuzzer = []

        duplOpts['state'] = False
        duplOpts['p'] = 0.02

        self.packetInfo = False

        self.inputLine.clear
        self.outputLine.clear
        interfaces = []

        proxy = True
        self.proxying()

        global fuzzerOpts
        fuzzerOpts = []


    '''Rotates currently used fuzzer according to user defined direction'''
    def rotateLeft(self):

        global currentFuzzer

        if len(currentFuzzer)<=1: return

        currentFuzzer.insert(0,currentFuzzer[len(currentFuzzer)-1])
        currentFuzzer.pop()

        self.Forwarder.fuzzerChange(currentFuzzer)
        
        self.updateGeneralField()


    def rotateRight(self):

        global currentFuzzer

        if len(currentFuzzer)<=1: return

        currentFuzzer.append(currentFuzzer[0])
        currentFuzzer.pop(0)

        self.Forwarder.fuzzerChange(currentFuzzer)

        self.updateGeneralField()


    def createInfoFields(self, layout):

        self.infoStyle="QTextEdit{border:2px solid darkgray;border-radius:3px;background-color:rgb(210,220,220);}"
        self.inactiveStyle="QTextEdit{border:2px solid darkgray;border-radius:3px;background-color:rgb(185,205,205);}"

        self.inLabel = QtGui.QLabel('Incoming traffic')
        self.inField = QtGui.QTextEdit()
        self.inField.setFocusPolicy(QtCore.Qt.NoFocus)
        self.inField.setStyleSheet(self.inactiveStyle)
        self.inField.setReadOnly(True)
        self.foLabel = QtGui.QLabel('Forwarded traffic')
        self.foField = QtGui.QTextEdit()
        self.foField.setFocusPolicy(QtCore.Qt.NoFocus)
        self.foField.setStyleSheet(self.inactiveStyle)
        self.foField.setReadOnly(True)
        self.fzLabel = QtGui.QLabel('Fuzzed traffic')
        self.fzField = QtGui.QTextEdit()
        self.fzField.setFocusPolicy(QtCore.Qt.NoFocus)
        self.fzField.setStyleSheet(self.inactiveStyle)
        self.fzField.setReadOnly(True)

        layout.addWidget(self.inLabel,0,0)
        layout.addWidget(self.inField,1,0,3,1)
        layout.addWidget(QtGui.QLabel(''),0,1)
        layout.addWidget(self.foLabel,0,2)
        layout.addWidget(self.foField,1,2)
        layout.addWidget(self.fzLabel,2,2)
        layout.addWidget(self.fzField,3,2)

        layout.setColumnStretch(1,10)


    def createGeneralField(self, layout):

        genStyle="QTextEdit{border-radius:7px;border:4px groove gray;background:lightgray;}"

        self.generalInfoField = QtGui.QTextEdit()
        self.generalInfoField.setFocusPolicy(QtCore.Qt.NoFocus)
        self.generalInfoField.setFixedWidth(230)
        self.generalInfoField.setMaximumHeight(270)
        self.generalInfoField.setMinimumHeight(220)
        self.generalInfoField.setStyleSheet(genStyle)
        self.generalInfoField.setReadOnly(True)

        layout.addWidget(QtGui.QLabel('<b>General info</b>'),0,0,QtCore.Qt.AlignCenter)
        layout.addWidget(self.generalInfoField,1,0,QtCore.Qt.AlignTop)

        self.updateGeneralField()


    '''Updates the information which is shown in "general info"-field.
    New text is created every time this function is called just to
    make things more simple. Only certain parts could be updated but
    that will be considered later'''
    def updateGeneralField(self):

        #Qstring is used and will be appended with relevant information
        infoText = QtCore.QString()
        
        infoText.append("<b>Fuzzing:</b> ")

        if len(fuzzerList)==0:
            infoText.append(self.disabledText)
        else:
            for fuzzer in fuzzerList:
                infoText.append("{} ".format(fuzzer))
            infoText.append("<br/>")
            infoText.append("<b>Current fuzzer:</b> {}<br/>".format(currentFuzzer[0]))

        if duplOpts['state']:
            infoText.append("<b>Duplicate probability:</b> {}<br/>".format(duplOpts['p']))
        infoText.append("<b>Proxy-mode:</b> ")

        if proxy:
            infoText.append(self.enabledText)
        else:
            infoText.append(self.disabledText)

        infoText.append("<b>Logging:</b> ")
        if loggingSettings['enabled']:
            infoText.append(self.enabledText)
            infoText.append("&nbsp;&nbsp;file - '{}',<br/>&nbsp;&nbsp;format - '{}'<br/>".format(loggingSettings['shortName'],loggingSettings['mode']))
        else:
            infoText.append(self.disabledText)

        #Check filtering settings and append string
        infoText.append("<b>Filtering:</b> ")
        if filtering['enabled']:
            infoText.append(self.enabledText)

            if filtering['protocols']:
                infoText.append("&nbsp;&nbsp;protocols - ")
                for proto in filtering['protocols']:
                    infoText.append("'{}' ".format(proto))
                infoText.append("<br/>")

            if filtering['level']!=0:
                infoText.append("&nbsp;&nbsp;level - {}<br/>".format(filtering['level']))

            if filtering['sa']!="":
                infoText.append("&nbsp;&nbsp;sour - {}".format(filtering['sa']))

            if filtering['sp']!=0 and filtering['sa']!="":
                infoText.append(":{}<br/>".format(filtering['sp']))
            elif filtering['sp']!=0:
                infoText.append("&nbsp;&nbsp;sour - {}<br/>".format(filtering['sp']))
            else: infoText.append("<br/>")

            if filtering['da']!="":
                infoText.append("&nbsp;&nbsp;dest - {}".format(filtering['da']))

            if filtering['dp']!=0 and filtering['da']!="":
                infoText.append(":{}<br/>".format(filtering['dp']))
            elif filtering['dp']!=0:
                infoText.append("&nbsp;&nbsp;dest - {}<br/>".format(filtering['dp']))
            else: infoText.append("<br/>")

        else:
            infoText.append(self.disabledText)

        self.generalInfoField.setText(infoText)


    def updateInfoFields(self, info, fieldNro):

        infoText = QtCore.QString()

        infoText.append("Packages received: {}".format(info['receivedNro']))
        self.fzField.setText("Packages fuzzed: {}".format(info['fuzzedNro']))
        self.foField.setText("Packages forwarded: {}".format(info['forwardedNro']))

        if self.infoCheck.isChecked() and fieldNro==0:
            try:
                infoText.append("<br/><br/>#{}, length: {}<br/>".format(info['receivedNro'], len(info['raw'])))

                if not fuzzerList:
                    infoText.append("<br/>-- Fuzzing not enabled --<br/>")
                    infoText.append("<br/>Package forwarded<br/>")

                if info['eth']:
                    infoText.append("<u>Ethernet header</u><br/>")
                    infoText.append("Source: {}<br/>".format(self.ethToInt(info['eth_mac_source'])))
                    infoText.append("Destination: {}<br/><br/>".format(self.ethToInt(info['eth_mac_destination'])))

                if info['ip']:
                    if info['ip_version']==4:
                        infoText.append("<u>IPv4 header</u><br/>")
                        infoText.append("IP source: {}<br/>".format(info['ip_source_address']))
                        infoText.append("IP destination: {}<br/><br/>".format(info['ip_destination_address']))

                if info['udp']:
                    infoText.append("<u>UDP header</u><br/>")
                    infoText.append("Source port: {}<br/>".format(info['udp_source_port']))
                    infoText.append("Destination port: {}<br/>".format(info['udp_destination_port']))
                elif info['tcp']:
                    infoText.append("<u>TCP header</u><br/>")
                    infoText.append("Source port: {}<br/>".format(info['tcp_source_port']))
                    infoText.append("Destination port: {}<br/>".format(info['tcp_destination_port']))
            except:
                pass
        
        self.inField.setText(infoText)


    '''
    Goes through important variables and makes sure there's enough
    defined settings to run a hoover. After that actual hoover funtions
    will be called.
    '''
    def startHoover(self):
        
        if not self.operate:
            global interfaces
            self.operate = True
            ###THERE IS SOMETIMES A BUG HAPPENING OVER HERE
            interfaces[0] = self.inputLine.text() #self.inputLine.displayText()
            interfaces[1] = self.outputLine.text() #self.outputLine.displayText()

            if interfaces[0]=="" or interfaces[1]=="":
                warning = displayWarning('Interface(s) not defined.')
                self.operate = False
                return

            if interfaces[0]==interfaces[1]:
                warning = displayWarning("Same interface for input and output is not allowed.")
                self.operate = False
                return

            if checkInterfaces(interfaces)==-1:
                warning = displayWarning("Defined interface doesn't exist.")
                self.operate = False
                return

            global loggingSettings
            if loggingSettings['enabled']:
                if loggingSettings['logfile']=="":
                    warning = displayWarning('No logfile defined.')
                    self.operate = False
                    return

            if self.infoCheck.checkState():
                self.packetInfo = True
            
            '''Enable and disable buttons'''
            self.resetButton.setEnabled(False)
            self.pauseButton.setEnabled(True)
            self.swapButton.setEnabled(True)
            self.fuzzerButton.setEnabled(False)
            self.fleft.setEnabled(True)
            self.fright.setEnabled(True)
            self.inputLine.setEnabled(False)
            self.outputLine.setEnabled(False)
            self.runButton.setText('\nHoover\nStop\n')
            self.runButton.setPalette(self.runRedPalette)
            self.inField.setStyleSheet(self.infoStyle)
            self.foField.setStyleSheet(self.infoStyle)
            self.fzField.setStyleSheet(self.infoStyle)

            '''Set states and start hoover's threads'''
            setRules(proxy,filtering, loggingSettings)
            self.Listener = Listener(interfaces)
            self.Forwarder = forwarderThread(interfaces[1],currentFuzzer,loggingSettings,duplOpts,fuzzerOpts)

            self.Forwarder.updateInfoDisplay.connect(self.updateInfoFields)
            
            self.Listener.start()
            self.Forwarder.start()

            '''If hoover is stopped, stop threads and enable/disable buttons.'''
        elif self.operate:
            self.operate = False
            '''Enable and disable buttons'''
            self.resetButton.setEnabled(True)
            self.pauseButton.setEnabled(False)
            self.swapButton.setEnabled(False)
            self.fuzzerButton.setEnabled(True)
            self.fleft.setEnabled(False)
            self.fright.setEnabled(False)
            self.inputLine.setEnabled(True)
            self.outputLine.setEnabled(True)
            self.runButton.setText('\nHoover\nStart\n')
            self.runButton.setPalette(self.runGreenPalette)
            self.inField.setStyleSheet(self.inactiveStyle)
            self.foField.setStyleSheet(self.inactiveStyle)
            self.fzField.setStyleSheet(self.inactiveStyle)

            self.Listener.shutDown()
            self.Forwarder.shutDown()
            resetVariables()

            self.inField.setText("")
            self.foField.setText("")
            self.fzField.setText("")

    
class displayWarning(QtGui.QMessageBox):
    def __init__(self, msg, parent=None):
        super(displayWarning,self).__init__(parent)
        self.setText("Error while initializing hoover.")
        self.setInformativeText(msg)
        self.setIcon(QtGui.QMessageBox.Warning)
        self.exec_()


if __name__=='__main__':
        
    app = QtGui.QApplication(sys.argv)
    app.setStyle(QtGui.QStyleFactory.create('GTK'))

    Hoover = NetworkHoover()
    Hoover.show()

    sys.exit(app.exec_())
